/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wii.elpro.dao.hb;

import com.wii.elpro.dao.BusinessPartnerDAOInterface;
import com.wii.elpro.dao.HibernateUtil;
import com.wii.elpro.entity.BusinessPartner;
import java.util.List;
import org.hibernate.Session;


/**
 *
 * @author hendro
 */
public class BusinessPartnerDAOImpl extends DAOGenericImpl implements BusinessPartnerDAOInterface {

    public BusinessPartner getBusinessPartner(long id) throws Exception {
        HibernateUtil.beginTransaction();
        Session session = HibernateUtil.getSession();
        try {
            return (BusinessPartner) session.load(BusinessPartner.class, id);
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<BusinessPartner> getBusinessPartners() throws Exception {
        HibernateUtil.beginTransaction();
        Session em = HibernateUtil.getSession();
        try {
            return em.createQuery("SELECT bp FROM BusinessPartner bp").list();
        } catch (Exception ex) {
            throw ex;
        }
    }

    public List<BusinessPartner> getBusinessPartnersByLevel(int plevel) throws Exception {
        HibernateUtil.beginTransaction();
        Session em = HibernateUtil.getSession();
        try {
            return em.createQuery("SELECT bp FROM BusinessPartner bp WHERE bp.partnerLevel=:input").setParameter("input", plevel).list();
        } catch (Exception ex) {
            throw ex;
        }
    }
}
